package au.com.langdale.gwt.client.pump;

import au.com.langdale.gwt.client.model.ModelInfo;
import au.com.langdale.gwt.client.model.Property;
import au.com.langdale.gwt.client.remote.RemoteList;

/**
 * A RemoteList that pull's its contents from the Pump service.<p>
 * 
 * A ModelInfo member must be provided to specify the class and sort key.<p>
 * 
 * TODO: The sort key is presently limited to a single property.
 * 
 * @author adv
 *
 */
public class PumpedList extends RemoteList {
	
	private ModelInfo modelInfo;

	protected void pull(int requestFirst, int requestQuota) {
		Property[] keys = modelInfo.getKeyProperties();
		if( keys.length > 0) {
			PumpFactory.getInstance().pull(modelInfo.getName(), keys[0].getFieldName(), requestFirst, requestQuota, this);
		}
		else {
			PumpFactory.getInstance().pull(modelInfo.getName(), requestFirst, requestQuota, this);
		}
	}

	public ModelInfo getModelInfo() {
		return modelInfo;
	}

	public void setModelInfo(ModelInfo modelInfo) {
		this.modelInfo = modelInfo;
	}
}